<template>
  <div class="app-container">
    课程列表

    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="coursequery.title" placeholder="课程名"/>
      </el-form-item>

      <el-form-item>
        <el-select v-model="coursequery.status" clearable placeholder="发布情况">
          <el-option value="Normal" label="已发布"/>
          <el-option value="Draft" label="未发布"/>
        </el-select>
      </el-form-item>

     
     

      <el-button type="primary" icon="el-icon-search" @click="getlist()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>

    <!-- 表格 -->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="170"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="title" label="名称" width="180" />
      <el-table-column prop="status" label="状态" width="180" >
         <template slot-scope="scope">
            {{scope.row.status=='Normal'?'已发布':'未发布'}}
        </template>
      </el-table-column>

      <el-table-column prop="viewCount" label="浏览数量" width="180" />
      <el-table-column prop="gmtCreate" label="创建时间" width="180" />

      <el-table-column label="操作" width="358" align="center">
        <template slot-scope="scope">
          <router-link :to="'/course/info/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">编辑课程基本信息</el-button>
          </router-link>
          <router-link :to="'/course/chapter/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">编辑课程大纲息</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除课程信息</el-button>
        </template>
      </el-table-column>
      
    </el-table>

  <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getlist"
    />

  </div>
</template>

<script>
import course from '@/api/teacher/course'
export default {
  data(){
    return{
            list:null, 
            page: 1,
            limit:5,
            total:0,
            coursequery:{
                
            }
    }

  },
  created(){
      this.getlist()
  },
  methods:{

        

      
        getlist(page=1){
             this.page=page
        course.getAllCourse(this.page,this.limit,this.coursequery).then(response=>{
               
                this.list=response.data.records
                this.total=response.data.total
                

        }).catch(error=>{
            console.log(error)
        })
        },
        //条件 清除
        resetData(){
                this.coursequery={}
                this.getlist()
        },
  //删除课程和相关数据
        removeDataById(id){
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            course.deleteCourseWith(id).then(response=>{
                this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.getlist()
            })
        })


          
            
        }
        
    }

}
</script>

<style>

</style>